package com.hopedove.tempdemo

import android.content.Intent
import android.os.Bundle
import androidx.activity.viewModels
import androidx.databinding.DataBindingUtil
import com.hopedove.base.BaseActivity
import com.hopedove.tempdemo.databinding.ActivityQueryNoticeListBinding
import com.hopedove.tempdemo.viewmodel.QueryNoticeListViewModel

class QueryNoticeList : BaseActivity() {

    lateinit var binding: ActivityQueryNoticeListBinding
    private val viewModel: QueryNoticeListViewModel by viewModels()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        binding = DataBindingUtil.setContentView(this, R.layout.activity_query_notice_list)

        binding.btnQuery.setOnClickListener {
            if (binding.etInputNo.text.isNotEmpty()) {
                viewModel.query(binding.etInputNo.text?.toString() ?: "")
            }
        }

        viewModel.navigate.observe(this, {
            if (it) {
                binding.etInputNo.setText("")
                startActivity(Intent(this, NoticeListShow::class.java))
            }
        })

        viewModel.loading.observe(this, { loading ->
            toggleWaitDialog(loading)
        })
    }


}